<?php
    if (!current_user_can('manage_options')) {
        wp_die('You do not have sufficient permissions to access this page.');
    }
    $number_row_all_deal = get_option('number_row_all_deal');
    $number_row_category = get_option('number_row_category');
    $number_row_store_single = get_option('number_row_store_single');
    $number_row_coming_soon = get_option('number_row_coming_soon');
    $number_row_past_deal = get_option('number_row_past_deal');
    $number_version_jump = get_option('number_version_jump');
    
?>
<div class="wrap">  
    <?php screen_icon('themes'); ?><h2>General</h2>
    <hr />
    <form method="POST" action="">  
        <table class="form-table"> 
            <tr valign="top">
                <th scope="row">
                    <label>Last deactive deals</label>   
                </th>  
                <td>  
                    <input id="last_deactive" type="text" /><a id="run_update_deal_now" style="font-size: 12px;cursor: pointer; ;">run now</a>
                </td>  
            </tr>
            <tr valign="top">
                <th scope="row">
                    <label>Last active deals</label>   
                </th>  
                <td>  
                    <input id="last_active" type="text" /><a id="run_active_deal_now" style="font-size: 12px;cursor: pointer; ;">run now</a>
                </td>                  
            </tr> 
            <tr valign="top">
                <th scope="row">
                    <label for="number_row_all_deal">Number row to display at all deals</label>   
                </th>  
                <td>  
                    <input value="<?php echo ($_POST['number_row_all_deal'] ? $_POST['number_row_all_deal'] : $number_row_all_deal); ?>" name="number_row_all_deal" type="text" style="width: 250px;"/>  
                </td>  
            </tr>
            <tr valign="top">
                <th scope="row">
                    <label for="number_row_category">Number row to display at category</label>   
                </th>  
                <td>  
                    <input value="<?php echo ($_POST['number_row_category'] ? $_POST['number_row_category'] : $number_row_category); ?>" name="number_row_category" type="text" style="width: 250px;"/>  
                </td>  
            </tr>
            <tr valign="top">
                <th scope="row">
                    <label for="number_row_store_single">Number row to display store single</label>   
                </th>  
                <td>  
                    <input value="<?php echo ($_POST['number_row_store_single'] ? $_POST['number_row_store_single'] : $number_row_store_single); ?>" name="number_row_store_single" type="text" style="width: 250px;"/>  
                </td>  
            </tr>
            <tr valign="top">
                <th scope="row">
                    <label for="number_row_coming_soon">Number row to display coming soon</label>   
                </th>  
                <td>  
                    <input value="<?php echo ($_POST['number_row_coming_soon'] ? $_POST['number_row_coming_soon'] : $number_row_coming_soon); ?>" name="number_row_coming_soon" type="text" style="width: 250px;"/>  
                </td>  
            </tr>
            <tr valign="top">
                <th scope="row">
                    <label for="number_row_past_deal">Number row to display past deal</label>   
                </th>  
                <td>  
                    <input value="<?php echo ($_POST['number_row_past_deal'] ? $_POST['number_row_past_deal'] : $number_row_past_deal); ?>" name="number_row_past_deal" type="text" style="width: 250px;"/>  
                </td>  
            </tr>
            <tr valign="top">
                <th scope="row">
                    <label for="number_version_jump">Number version jumb page</label>   
                </th>  
                <td>  
                    <input value="<?php echo ($_POST['number_version_jump'] ? $_POST['number_version_jump'] : $number_version_jump); ?>" name="number_version_jump" type="text" style="width: 250px;"/>  
                </td>  
            </tr>
        </table>
        <p>  
            <input type="submit" value="Save settings" class="button-primary"/>
        </p>   
    </form>  
</div> 

<?php
        if(
            isset($_POST['number_row_all_deal']) ||
            isset($_POST['number_row_category'])
        )
        {
            //update facebook page url
            $row_all_deals = esc_attr($_POST['number_row_all_deal']);
            update_option('number_row_all_deal',$row_all_deals);
            $new_category = esc_attr($_POST["number_row_category"]);
            update_option('number_row_category',$new_category);
            $new_store = esc_attr($_POST["number_row_store_single"]);
            update_option('number_row_store_single',$new_store);
            $new_coming = esc_attr($_POST["number_row_coming_soon"]);
            update_option('number_row_coming_soon',$new_coming);
            $new_past = esc_attr($_POST["number_row_past_deal"]);
            update_option('number_row_past_deal',$new_past);
            $new_number_version = esc_attr($_POST["number_version_jump"]);
            update_option('number_version_jump',$new_number_version);
            // print success message
            echo '<div id="message" class="updated">Settings saved</div>';
        }
?>